package cn.ilovese.collect.controller.recommend;

import cn.ilovese.collect.service.recommend.RecommendService;
import cn.ilovese.collect.vo.NullVO;
import cn.ilovese.collect.vo.ResultVO;
import cn.ilovese.collect.vo.recommend.RecommendRuleHaveNameVO;
import cn.ilovese.collect.vo.recommend.RecommendRuleVO;
import cn.ilovese.collect.vo.task.TaskRecommendVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/recommend")
public class RecommendController {
    @Resource
    RecommendService recommendService;

    //创建推荐规则
    @PostMapping("/create")
    public ResultVO<RecommendRuleVO> createRecommendRule(@RequestBody RecommendRuleVO recommendRuleVO){
        return recommendService.createRecommendRule(recommendRuleVO);
    }

    //更新推荐规则
    @PostMapping("/updateRule")
    public ResultVO<RecommendRuleVO> updateRecommendRule(@RequestBody RecommendRuleVO recommendRuleVO){
        return recommendService.updateRecommendRule(recommendRuleVO);
    }

    //获得所有的规则，众包测试工人页面和众包测试发包方需要，都只需要id和name即可
    @GetMapping("/getAllRules")
    public ResultVO<List<RecommendRuleHaveNameVO>> getAllRecommendRules(){
        return recommendService.getAllRecommendRules();
    }

    //删除推荐规则
    @GetMapping("/deleteRule/{ruleid}")
    public ResultVO<NullVO> deleteRecommendRule(@PathVariable Integer ruleid){
        return recommendService.deleteRecommendRule(ruleid);
    }

    //获取某条规则的具体信息
    @GetMapping("/getrule/{ruleid}")
    public ResultVO<RecommendRuleVO> getRecommendRuleDetail(@PathVariable Integer ruleid){
        return recommendService.getRecommendRuleDetail(ruleid);
    }

    //使用推荐规则，推荐规则三种策略使用比例进行计算匹配度
    @GetMapping("/useRule")
    public ResultVO<List<TaskRecommendVO>> executeRecommendRule(@RequestParam Integer ruleid, @RequestParam Integer workerid){
        return recommendService.executeRecommendRule(ruleid,workerid);
    }
}
